<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/6
 * Time: 15:19
 */
header('Access-Control-Allow-Origin: *');//跨域


if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $uname = $_REQUEST["uname"];
    $upwd = $_REQUEST["upwd"];
}
//1.链接数据量，ip，用户名，密码，数据库名称
$severName = '127.0.0.1';//数据库名称ip
$dbUser = 'root';//用户名
$dbPwd = '';//密码
$dbName = 'hz1706';//库名称

$conn = new mysqli($severName, $dbUser, $dbPwd, $dbName);

mysqli_query($conn, "set names utf8");//配置一个connection字符串，设置字符集
if ($conn->connect_error) {//->相当于js里面的  .  属性
    $arr = array();
    $arr["status"] = 0;
    $arr["msg"] = "数据库失败";
    print_r(json_encode($arr));//以json方式告诉客户端(前端)；
}
//执行sql语句
$sql = "SELECT*FROM userinfo WHERE uname='" . $uname . "' AND upwd='" . $upwd . "'";
//mysqli_query($conn,$sql);//通过query的方法去执行自己制定的sql语句
$result = $conn->query($sql);//返回一个对象
//判断：如果数据库里返回的结果大于1或等于1，表示登录成功，否则失败;
if ($result->num_rows >= 1) {
//登录成功；
    $arr = array();
    $arr["status"] = 1;
    $arr["msg"] = "登录成功";
    print_r(json_encode($arr));
} else {
    $arr = array();
    $arr["status"] = 0;
    $arr["msg"] = "用户名或密码错误";
    print_r(json_encode($arr));
}
